package com.sgb.kjwl.viewmodel.manage;

import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.manage.WebsiteInfoEntity;
import com.sgb.kjwl.repository.ManageRepertory;
import com.sgb.kjwl.view.ui.fragment.manage.IntroductionForWebsite;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.HashMap;
import java.util.Map;

public class IntroductionForWebsiteModel extends BaseViewModel {

    private IntroductionForWebsite fragment;

    private MutableLiveData<WebsiteInfoEntity> websiteInfoEntityMutableLiveData = new MutableLiveData<>();

    public IntroductionForWebsiteModel(IntroductionForWebsite fragment) {
        this.fragment = fragment;
    }

    public IntroductionForWebsiteModel(ManageRepertory repertory) {
    }

    public MutableLiveData<WebsiteInfoEntity> getWebsiteInfoEntityMutableLiveData() {
        return websiteInfoEntityMutableLiveData;
    }


    //-----网站详情----------------------------------------------------------------
    public void getWebsiteInfo(String siteNo, int siteType) {
        Map<String, String> map = new HashMap();
        map.put("siteNo", siteNo);
        map.put("siteType", siteType + "");
        APIManager.getInstance().getWebsiteInfoAPI().getSiteInfo(map).enqueue(new ICallBack<BaseEntity<WebsiteInfoEntity>>(true, true) {

            @Override
            public void onSuccess(BaseEntity<WebsiteInfoEntity> data) {
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (fragment != null) {
                        fragment.showWebsiteInfo(data.getData());
                    } else {
                        websiteInfoEntityMutableLiveData.postValue(data.getData());
                    }
                }
            }
        });
    }
}
